package smetana.modules.ui.actions;

import com.google.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.pivot.wtk.Action;

/**
 *
 * @author dmitry.mamonov
 */
public abstract class AbstractAction extends Action {
    protected Logger log = Logger.getLogger(getClass());

    @Inject
    CreateDocumentAction actionCreate;

    @Inject
    EditDocumentAction actionEdit;

    @Inject
    SaveDocumentAction actionSave;

    @Inject
    DeleteDocumentAction actionDelete;

    @Inject
    ExportDocumentAction actionExport;

    @Inject
    PrintDocumentAction actionPrint;

    public AbstractAction(boolean enabled) {
        super(enabled);
        registerGlobalAction();
    }

    public AbstractAction() {
        super();
        registerGlobalAction();
    }

    private void registerGlobalAction(){
        String className = getClass().getSimpleName();
        String actionId = className.replace("Action", "");
        if ((actionId+"Action").equals(className)==false){
            throw new IllegalStateException("Class name must be ended with word: 'Action'");
        }
        String actionName = "action"+actionId;
        if( Action.getNamedActions().containsKey(actionName)==true){
            throw new IllegalStateException("Not allowed to instantiate "+getClass()+" more than once");
        }
        Action.getNamedActions().put(actionName, this);
    }


    
}
